<template>
    <div>创作页</div>
    <button @click="handleSend">发布创作</button>
</template>

<script setup lang="ts">
import userSocket from "@/utils/websocket"
import { onMounted, ref } from "vue"

let msg = ref<string>('')

const handleMessage = (e: any) => {
    
}
const ws: any = userSocket(handleMessage)

// 点击发送
const handleSend = () => {
    // if(msg.value.trim().length != 0) {
    //     const data = {
    //         msg: msg.value
    //     }
    // }
    ws.send(JSON.stringify({
        msg: '发布了一个创作'
    }))
    // return ''
}


// MyComponent.vue

// import { createWebSocket } from '@/utils/websocket.js'

// export default {
//   mounted() {
//     const ws = createWebSocket(
//       'ws://example.com/socketserver',
//       () => console.log('WebSocket opened'),
//       event => console.log('WebSocket message', event.data),
//       error => console.error('WebSocket error', error),
//       event => console.log('WebSocket closed', event)
//     )
//     ws.send('Hello Server!')
//   }
// }

onMounted(() => {

})
</script>

<style lang="less" scoped>

</style>